package org.zcl.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zcl.api.ApiException;
import org.zcl.api.ApiResponse;

/**
 * .
 *
 * @author zhuchenglin
 * @since 2024/4/22 16:14
 */
@ControllerAdvice
@Slf4j
public class GlobalControllerAdvice {

    @ExceptionHandler(ApiException.class)
    @ResponseBody
    public ApiResponse<?> apiExceptionHandler(ApiException apiException) {
        log.warn(apiException.getMessage());
        return new ApiResponse<>().returnFailure(apiException.getMessage());
    }

}
